/**
 * 
 * Copyright (C) 2011 Cody Stoutenburg . All rights reserved.
 *
 *       This program is free software; you can redistribute it and/or
 *       modify it under the terms of the GNU Lesser General Public License
 *       as published by the Free Software Foundation; either version 2.1
 *       of the License, or (at your option) any later version.
 *
 *       This program is distributed in the hope that it will be useful,
 *       but WITHOUT ANY WARRANTY; without even the implied warranty of
 *       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *       GNU Lesser General Public License for more details.
 *
 *       You should have received a copy of the GNU Lesser General Public License
 *       along with this program; if not, write to the Free Software
 *       Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. 
 * 
 */
package net.alteiar.plateform.game;

import java.io.Serializable;

/**
 * @author Cody Stoutenburg
 * 
 */

public class Rectangle2D implements Serializable {
	private static final long serialVersionUID = 1L;

	private Double x;
	private Double y;

	private final Double width;
	private final Double height;

	public Rectangle2D(Double x, Double y, Double width, Double height) {
		this.x = x;
		this.y = y;
		this.width = width;
		this.height = height;
	}

	public Double getX() {
		return x;
	}

	public Double getY() {
		return y;
	}

	public Double getWidth() {
		return width;
	}

	public Double getHeight() {
		return height;
	}

	public void setLocation(double x, double y) {
		this.x = x;
		this.y = y;
	}

	public Boolean intersects(Rectangle2D rectangle) {
		Boolean haveIntersection = true;
		if (this.x > rectangle.getX() + rectangle.getWidth()) {
			haveIntersection = false;
		} else if (this.x + this.width < rectangle.getX()) {
			haveIntersection = false;
		} else if (this.y > rectangle.getY() + rectangle.getHeight()) {
			haveIntersection = false;
		} else if (this.y + this.getHeight() < rectangle.getY()) {
			haveIntersection = false;
		}
		return haveIntersection;
	}
}
